﻿// ===============================================================================
// Project Name        :    Gfw.BLL.Basic.Account
// Project Description :    
// ===============================================================================
// Class Name          :    UserAmount
// Namespace:          :    Gfw.BLL.Basic.Account
// Class Version       :    v1.0.0.0
// Class Description   :    
// CLR Version:        :    4.0.30319.17626
//Author               :    lif
// Machine             :    ADICO-PC
// Create Time         :    2012/6/24 13:56:24
// Update Time         :    2012/6/24 13:56:24
// ===============================================================================
// Copyright © lif 2012 . All rights reserved.
// ===============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gfw.BLL.Basic.Facilities;
using Gfw.BLL.Basic.Stock;
using Gfw.BLL.Basic.User;
using Gfw.Infrastructure.Account;
using Gfw.Infrastructure.ExceptionImpl;
using Gfw.Infrastructure.Facilities;
using Gfw.Models.Account;
using Gfw.Repositories.Account;
using Gfw.Repositories.Admin;
using Gfw.Repository;
using Gfw.Web.Models.Account;
using Gfw.Web.Models.User;

namespace Gfw.BLL.Basic.Account
{
    /// <summary>
    /// 用户账户
    /// </summary>
    public class UserAccountLogic
    {
        #region Const Fields

        private const int EXPIREDAY = 6; // 5天过期，第6天凌晨结算

        #endregion

        #region 用户帐户信息
        /// <summary>
        /// 获得用户的帐户信息
        /// </summary>
        /// <param name="userId">用户的ID</param>
        /// <returns></returns>
        public static UserAccountModel GetUserAccount(string userId)
        {
            ActUserAccountinformationRepository repository = new ActUserAccountinformationRepository();
            var userAccount = repository.Get(userId);
            var model = new UserAccountModel()
                            {
                                Cash = userAccount.Cash,
                                ElectronicMoney = userAccount.ElectronicMoney
                            };
            return model;

        }

        public static UserAccountSummaryModel GetUserAccountSummary(string userId)
        {
            ActUserAccountinformationRepository repository = new ActUserAccountinformationRepository();
            var userAccount = repository.Get(userId);
            var model = new UserAccountSummaryModel()
            {
                Cash = userAccount.Cash,
                ElectronicMoney = userAccount.ElectronicMoney
            };

            var user = UserLogic.GerUserInfo(userId);
            model.LoginName = user.LoginName;
            try
            {
                var stock = UsAccountLogic.GetUserAccount(userId);
                model.StockAccount = stock.StockMoney;
                model.OwnedCount = stock.OwnedCount;
            }
            catch (Exception exp)
            {

            }
            return model;
        }

        #endregion

        #region 创建用户帐户
        /// <summary>
        /// 创建新的用户帐户
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="work"></param>
        public static void CreateNewUserAccount(string userId, UnitOfWork work)
        {
            ActUserAccountinformationRepository accountRepository = new ActUserAccountinformationRepository();
            ActUserAccountinformation aua = new ActUserAccountinformation()
                                                {
                                                    Userid = userId,
                                                    Cash = 0,
                                                    ElectronicMoney = 0,
                                                    Status = (int)AccountStatusEnum.NotActive
                                                };

            accountRepository.Save(aua, work);
        }

        #endregion

        #region 用户内部货币转换
        public static void ToECurrency(string userId, decimal count)
        {
            ToECurrencyFacility facility = new ToECurrencyFacility(userId, count);
            facility.Execute();
        }

        #endregion

        #region 转账

        /// <summary>
        /// 普通转账
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="model"></param>
        public static void Transfer(string userId, TransferModel model)
        {
            var userRep = new UsrUserRepository();
            var user = userRep.Get(userId);
            var toUser = userRep.GetUserByLoginName(model.ToUser);
            if (toUser == null)
                throw new GfwVerifyException("转入帐户不存在！");

            TransferFacilityImpl facility = new TransferFacilityImpl(user, toUser, model.Count);
            facility.Execute();
        }

        /// <summary>
        /// 普通转账查询
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<TransferQueryModel> TransferQuery(string userId, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActUserBargain4emoneyRepository repository = new ActUserBargain4emoneyRepository();
            int[] tradeTypes = new int[] { (int)UserTradeTypeEnum.In, (int)UserTradeTypeEnum.Out };
            var hs = repository.Query(userId, tradeTypes, start, end, pageIndex - 1, pageSize, out totalSize);
            var models = new List<TransferQueryModel>();
            foreach (var h in hs)
            {
                models.Add(h.CopyTo<TransferQueryModel>());
            }
            return models;
        }


        /// <summary>
        /// 担保转账入中间方（会员电子币之间交易）
        /// </summary>
        /// <param name="model"></param>
        /// <param name="bankCardNo">账号</param>
        /// <param name="bankName">开户行（四大银行 + 财付通 + 支付宝）字典</param>
        /// <param name="bankUserName">开户名</param>
        public static void WarrantTransfer(WarrantTransferModel model, string bankName, string bankCardNo,
            string bankUserName)
        {
            var userRep = new UsrUserRepository();
            var user = userRep.Get(model.UserID);
            var toUser = userRep.GetUserByLoginName(model.ToUser);

            if (user == null)
                throw new GfwVerifyException("登录超时！");
            if (toUser == null)
                throw new GfwVerifyException("转入帐户不存在！");

            TransferFacility.ExecuteWarrantOut(user, toUser, model.Count,
                bankName, bankCardNo, bankUserName);
        }

        /// <summary>
        /// 担保转账查询
        /// </summary>
        /// <param name="userId">当前用户id</param>
        /// <param name="selectStatus">所选状态</param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<WarrantTransferQueryModel> WarrantTransferQuery(string userId, string selectStatus, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActUserWarrantRepository repository = new ActUserWarrantRepository();

            WarrantStatusEnum outWarrantStatus;
            int status = int.MinValue;

            if (Enum.TryParse<WarrantStatusEnum>(selectStatus, true, out outWarrantStatus))
            {
                status = (int)outWarrantStatus;
            }

            var hs = repository.Query(userId, status, start, end, pageIndex, pageSize, out totalSize);
            var models = new List<WarrantTransferQueryModel>();
            foreach (var h in hs)
            {
                WarrantTransferQueryModel model = new WarrantTransferQueryModel()
                {
                    CurrentUserID = userId, // 当前登录用户ID
                    UserID = h.Userid,
                    ToUserID = h.ToUserId,
                    UserLoginName = h.UserLoginName,
                    ToUserLoginName = h.ToUserLoginName,
                    TradeDate = h.TradeDate,
                    Money = h.Money,
                    TradeAbstract = h.TradeAbstract,
                    RemainDate = h.TradeDate.HasValue ? h.TradeDate.Value.AddDays(EXPIREDAY).Date : h.TradeDate,
                };

                switch (h.Status)
                {
                    case (int)WarrantStatusEnum.Progress:
                        model.Status = "担保进行中";
                        break;
                    case (int)WarrantStatusEnum.Transfer:
                        model.Status = "买家已转账";
                        break;
                    case (int)WarrantStatusEnum.Acknowledge:
                        model.Status = "卖家已确认";
                        break;
                    case (int)WarrantStatusEnum.Return:
                        model.Status = "担保撤销";
                        break;

                    default:
                        model.Status = string.Empty;
                        break;
                }

                models.Add(model);
            }

            return models;
        }


        /// <summary>
        /// 查询担保详情
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="toUserID"></param>
        /// <param name="tradeDate"></param>
        /// <param name="selectStatus">所选状态</param>
        /// <param name="current">当前用户ID</param>
        /// <returns></returns>
        public static WarrantDetailModel GetWarrantByBothUserIDAndTradeDate(string userID,
            string toUserID, DateTime tradeDate, string selectStatus, string current)
        {
            ActUserWarrantRepository repository = new ActUserWarrantRepository();
            ActUserWarrant userWarrant = repository.GetWarrantByBothUserIDAndTradeDate(userID, toUserID,
                tradeDate);

            if (userWarrant == null)
                return null;

            WarrantDetailModel model = new WarrantDetailModel();

            model = userWarrant.CopyTo<WarrantDetailModel>();
            model.RemainDate = userWarrant.TradeDate.HasValue ? userWarrant.TradeDate.Value.AddDays(EXPIREDAY).Date : userWarrant.TradeDate;
            model.Status = selectStatus;
            model.CurrentUserID = current;

            return model;
        }


        /// <summary>
        /// 买家已转账
        /// </summary>
        /// <param name="model"></param>
        public static void WarrantTransferHasTransfer(WarrantDetailModel model)
        {
            if (model == null)
                return;

            ActUserWarrantRepository repository = new ActUserWarrantRepository();
            ActUserWarrant userWarrant = repository.GetWarrantByBothUserIDAndTradeDate(model.Userid, model.ToUserId, model.TradeDate.Value);

            if (userWarrant != null)
            {

                if (userWarrant.Status != (int)WarrantStatusEnum.Progress)
                    throw new GfwVerifyException("不能进行转账操作！");

                userWarrant.BankSerialNo = model.BankSerialNo;
                userWarrant.TransferOrWithdrawDate = DateTime.Now;
                userWarrant.Status = (int)WarrantStatusEnum.Transfer;
                userWarrant.TradeAbstract = "买家已转账，等待卖家确认";

                repository.Update(userWarrant);
            }
        }

        /// <summary>
        /// 买家撤单
        /// </summary>
        /// <param name="buyerID">买家ID</param>
        /// <param name="buyerLoginName">买家登录名</param>
        /// <param name="toSellerID">卖家ID</param>
        /// <param name="tradeDate">担保时间</param>
        public static void WarrantTransferReturn(string buyerID, string buyerLoginName, string toSellerID,
            DateTime tradeDate)
        {
            TransferFacility.ExecuteWarrantReturn(buyerID, buyerLoginName, toSellerID, tradeDate);
        }

        /// <summary>
        /// 卖家已确认
        /// </summary>
        /// <param name="userID">发起（转出）用户ID</param>
        /// <param name="userLoginName">发起（转出）用户登录名</param>
        /// <param name="toUserID">转入用户ID</param>
        /// <param name="tradeDate">担保时间</param>
        public static void WarrantTransferAck(string userID, string userLoginName, string toUserID, DateTime tradeDate)
        {
            TransferFacility.ExecuteWarrantIn(userID, userLoginName, toUserID, tradeDate);
        }

        #endregion

        #region 充值

        /// <summary>
        /// 会员充值
        /// </summary>
        /// <param name="model">充值记录表</param>
        public static void Recharge(UserRechargeModel model)
        {
            if (model == null)
                throw new GfwVerifyException("充值的参数不正确！");

            RechargeFacility facility = new RechargeFacility(model.UserID, model.BankCardNo,
                model.BankName, model.BankUserName, model.RechargeMoney, model.BankSerialNo,
                model.HandlerID, model.Status);
            facility.Execute();
        }

        /// <summary>
        /// 充值记录查询（后台管理员）
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="loginName">用户登录名：不用于查询条件，只是赋值作用</param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <param name="countRecharge"></param>
        /// <param name="sumRecharge"></param>
        /// <param name="maxRecharge"></param>
        /// <param name="minRecharge"></param>
        /// <returns></returns>
        public static IList<UserRechargeModel> RechargeQuery(string userID, string loginName, DateTime start, DateTime end, int pageIndex, int pageSize,
            out int totalSize, out int countRecharge, out decimal sumRecharge, out decimal maxRecharge, out decimal minRecharge)
        {
            ActCompanyRechargeRepository _rechargeRepository = new ActCompanyRechargeRepository();
            var _rechargeList = _rechargeRepository.QueryRecharge(userID, start, end, pageIndex, pageSize, out totalSize, out countRecharge, out sumRecharge, out maxRecharge, out minRecharge);

            List<UserRechargeModel> _rechargeModelList = new List<UserRechargeModel>();
            if (_rechargeList != null && _rechargeList.Count() > 0)
            {
                foreach (ActCompanyRecharge _item in _rechargeList)
                {
                    UserRechargeModel _recharge = new UserRechargeModel()
                    {
                        UserID = _item.Userid,
                        LoginName = loginName,
                        BankName = _item.BankName,
                        BankCardNo = _item.BankCardNo,
                        BankUserName = _item.BankUserName,
                        RechargeMoney = _item.RechargeMoney,
                        RechargeDate = _item.RechargeDate.Value,
                        BankSerialNo = _item.BankSerialNo,
                        HandlerID = _item.Handlerid,
                        Status = _item.Status,
                    };

                    _rechargeModelList.Add(_recharge);
                }
            }

            return _rechargeModelList;
        }

        /// <summary>
        /// 充值记录查询（前台会员）
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<RechargeQueryModel> RechargeQuery(string userId, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActUserBargain4emoneyRepository repository = new ActUserBargain4emoneyRepository();
            int[] tradeTypes = new int[] { (int)UserTradeTypeEnum.Recharge };
            var hs = repository.Query(userId, tradeTypes, start, end, pageIndex - 1, pageSize, out totalSize);
            var models = new List<RechargeQueryModel>();
            foreach (var h in hs)
            {
                models.Add(h.CopyTo<RechargeQueryModel>());
            }
            return models;
        }

        #endregion

        #region 提现

        /// <summary>
        /// 提现申请（会员申请）
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="count">申请金额</param>
        /// <param name="bankCardNo">账号</param>
        /// <param name="bankName">开户行（四大银行 + 财付通 + 支付宝）字典</param>
        /// <param name="bankUserName">开户名</param>
        public static void CashApply(string userID, long count, string bankName, string bankCardNo,
            string bankUserName)
        {
            CashFacility facility = new CashFacility(userID, count, bankName, bankCardNo, bankUserName);
            facility.ExecuteApply();
        }

        /// <summary>
        /// 提现查询（前台会员）
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<CashQueryModel> CashQuery(string userId, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActUserBargain4cashRepository repository = new ActUserBargain4cashRepository();
            int[] tradeTypes = new int[] { (int)UserTradeTypeEnum.ToCash };
            var hs = repository.Query(userId, tradeTypes, start, end, pageIndex - 1, pageSize, out totalSize);
            var models = new List<CashQueryModel>();
            foreach (var h in hs)
            {
                models.Add(h.CopyTo<CashQueryModel>());
            }
            return models;
        }

        /// <summary>
        /// 提现查询（后台管理员）
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="loginName">只用于显示，不参数逻辑！</param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="cashType"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<CashQueryCmpModel> CashQuery(string userID, string loginName, string cashType, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActCompanyCashRepository repository = new ActCompanyCashRepository();
            int status = int.MaxValue; // 标志：表示查找“全部”

            switch (cashType)
            {
                case "审核中":
                    status = (int)CashStatusEnum.Wait;
                    break;
                case "审核通过":
                    status = (int)CashStatusEnum.Pass;
                    break;
                case "审核不通过":
                    status = (int)CashStatusEnum.Cancel;
                    break;
            }

            var hs = repository.GetCashByStatus(userID, status, start, end, pageIndex - 1, pageSize, out totalSize);
            List<CashQueryCmpModel> modelList = new List<CashQueryCmpModel>();

            if (hs != null && hs.Count() > 0)
            {
                foreach (ActCompanyCash h in hs)
                {
                    CashQueryCmpModel model = new CashQueryCmpModel()
                    {
                        UserID = h.Userid,
                        BankUserName = h.BankUserName,
                        BankName = h.BankName,
                        LoginName = string.IsNullOrWhiteSpace(loginName) ? UserLogic.GetLoginNameByUserID(h.Userid) : loginName,
                        Money = h.Money,
                        RequireDate = h.RequireDate,
                    };

                    switch (h.Status)
                    {
                        case (int)CashStatusEnum.Cancel:
                            model.Status = "审核不通过";
                            break;
                        case (int)CashStatusEnum.Wait:
                            model.Status = "审核中";
                            break;
                        case (int)CashStatusEnum.Pass:
                            model.Status = "审核通过";
                            break;

                        default:
                            model.Status = string.Empty;
                            break;
                    }

                    modelList.Add(model);
                }
            }

            return modelList;
        }

        /// <summary>
        /// 提现审核操作（后台管理员）
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="applyDate"></param>
        /// <param name="count">提现申请金额</param>
        /// <param name="checkID"></param>
        /// <param name="bankSerialNo"></param>
        /// <param name="tradeAbstract"></param>
        /// <param name="isCheckPass">true: 审核通过；false: 审核不通过</param>
        public static void CashCheck(string userID, DateTime applyDate, long count, string checkID,
            string bankSerialNo, string tradeAbstract, bool isCheckPass = true)
        {
            CashFacility facility = new CashFacility(userID, applyDate, count, checkID, bankSerialNo, tradeAbstract);

            if (isCheckPass) // 审核通过
                facility.Execute();
            else // 审核不通过
                facility.ExecuteCancel();
        }

        /// <summary>
        /// 获取会员提现申请信息（后台管理员）
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="applyDate"></param>
        /// <returns></returns>
        public static CashQueryCmpModel GetUserCashApplyInfo(string userID, DateTime applyDate)
        {
            ActCompanyCashRepository repository = new ActCompanyCashRepository();
            var h = repository.GetCashByUserIDAndApplyDate(userID, applyDate);

            if (h != null)
            {
                CashQueryCmpModel model = new CashQueryCmpModel()
                {
                    UserID = h.Userid,
                    LoginName = UserLogic.GetLoginNameByUserID(userID),
                    BankCardNo = h.BankCardNo,
                    BankUserName = h.BankUserName,
                    BankName = h.BankName,
                    Money = h.Money,
                    RequireDate = h.RequireDate,
                };

                return model;
            }

            return null;
        }

        #endregion

        #region 收取会员修改资料手续费

        /// <summary>
        /// 收取会员修改资料手续费，每次100元
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        public static void GetCommission(string userID, string userName)
        {
            UserInfoCommissionFacility facility = new UserInfoCommissionFacility(userID, userName);
            facility.Execute();
        }

        #endregion

        #region 各种货币查询集合——X:Cash | D:EMoney | G:Stock | 动态奖金

        /// <summary>
        /// 用户现金币交易明细
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="tradeType"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<CashQueryModel> Bargain4CashQuery(string userId, string tradeType,
            DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            int[] tradeTypes = null;

            UserTradeTypeEnum outTradeType;
            if (Enum.TryParse<UserTradeTypeEnum>(tradeType, true, out outTradeType))
            {
                tradeTypes = new int[] { (int)outTradeType };
            }

            ActUserBargain4cashRepository repository = new ActUserBargain4cashRepository();
            var hs = repository.Query(userId, tradeTypes, start, end, pageIndex - 1, pageSize, out totalSize);

            var models = new List<CashQueryModel>();
            foreach (var h in hs)
            {
                CashQueryModel temp = h.CopyTo<CashQueryModel>();
                temp.TradeType = EnumHelper.GetDisplayAttribute<UserTradeTypeEnum>(h.TradeType.ToString());

                models.Add(temp);
            }
            return models;
        }

        /// <summary>
        /// 用户电子币交易明细
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="tradeType"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalSize"></param>
        /// <returns></returns>
        public static IList<TransferQueryModel> Bargain4EMoneyQuery(string userId, string tradeType,
            DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            int[] tradeTypes = null;

            UserTradeTypeEnum outTradeType;
            if (Enum.TryParse<UserTradeTypeEnum>(tradeType, true, out outTradeType))
            {
                tradeTypes = new int[] { (int)outTradeType };
            }

            ActUserBargain4emoneyRepository repository = new ActUserBargain4emoneyRepository();
            var hs = repository.Query(userId, tradeTypes, start, end, pageIndex - 1, pageSize, out totalSize);

            var models = new List<TransferQueryModel>();
            foreach (var h in hs)
            {
                TransferQueryModel temp = h.CopyTo<TransferQueryModel>();
                temp.TradeType = EnumHelper.GetDisplayAttribute<UserTradeTypeEnum>(h.TradeType.ToString());

                models.Add(temp);
            }
            return models;
        }

        //////////////////////////////////////////////////////////////////////////
        /* 这里是菲总的 股票 与 动态奖金 查询 */
        //////////////////////////////////////////////////////////////////////////

        #region 动态奖金查询

        public static IList<AwardQueryListModel> AwardQuery(string userId, int tradeType, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalSize)
        {
            ActUserDynamicawardRepository rep = new ActUserDynamicawardRepository();
            var list = rep.Query(userId, tradeType, start, end, pageIndex, pageSize, out totalSize);
            var result = new List<AwardQueryListModel>();
            foreach (var l in list)
            {

                result.Add(l.CopyTo<AwardQueryListModel>());
            }
            return result;
        }
        #endregion

        #endregion

        #region 现金币交易查询
        public static List<BargainCashModel> BargainCashQuery(string userId, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalPage)
        {
            totalPage = 0;
            ActUserBargain4cashRepository rep = new ActUserBargain4cashRepository();
            var list = rep.Query(userId, null, start, end, pageIndex, pageSize, out totalPage);
            var result = new List<BargainCashModel>();
            foreach (var l in list)
            {
                result.Add(new BargainCashModel()
                {
                    Balance = l.Balance,
                    Income = l.Income,
                    Outlay = l.Outlay,
                    TradeAbstract = l.TradeAbstract,
                    TradeDate = l.TradeDate,
                    TradeType = l.TradeType
                });
            }
            return result;
        }

        #endregion

        #region 电子币交易查询
        public static List<BargainEmoneyModel> BargainEmoneyQuery(string userId, DateTime? start, DateTime? end, int pageIndex, int pageSize, out int totalPage)
        {
            totalPage = 0;
            ActUserBargain4emoneyRepository rep = new ActUserBargain4emoneyRepository();
            var list = rep.Query(userId, null, start, end, pageIndex, pageSize, out totalPage);
            var result = new List<BargainEmoneyModel>();
            foreach (var l in list)
            {
                result.Add(new BargainEmoneyModel()
                {
                    Balance = l.Balance,
                    Income = l.Income,
                    Outlay = l.Outlay,
                    TradeAbstract = l.TradeAbstract,
                    TradeDate = l.TradeDate,
                    TradeType = l.TradeType
                });
            }
            return result;
        }

        #endregion

        public static void CreateAccount(string userId)
        {
            ActUserAccountinformation act = new ActUserAccountinformation()
                                                {
                                                    Userid = userId,
                                                    Cash = 0,
                                                    ElectronicMoney = 0,
                                                    Status = 0
                                                };
            ActUserAccountinformationRepository repository = new ActUserAccountinformationRepository();
            repository.Save(act);
        }
    }
}
